//
//  StatsViewController.m
//  Care With Friends
//
//  Created by Versatile Systems, Inc on 11/5/13.
//  Copyright (c) 2013 Muludiang. All rights reserved.
//

#import "StatsViewController.h"
#import "CWFData.h"
#import "PlayerProfileViewController.h"

@interface StatsViewController ()

@end

@implementation StatsViewController

@synthesize friendStats;
@synthesize globalStats;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // return number of rows
    if (tableView == globalStats){
        return [tempGlobalArray count];
    }
    else
    {
    return [tempFriendsArray count];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"GlobalCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    
    
    if (tableView == globalStats){
        [cell.textLabel setText:[NSString stringWithFormat:@"%@ %@",[[tempGlobalArray objectAtIndex:indexPath.row] valueForKey:@"first_name"],[[tempGlobalArray objectAtIndex:indexPath.row] valueForKey:@"last_name"]]];
    [cell.detailTextLabel setText:[NSString stringWithFormat:@"Score: %@",[[tempGlobalArray objectAtIndex:indexPath.row ] valueForKey:@"score" ]]];
    }

    //[cell setAccessoryType:UITableViewCellAccessoryDetailButton];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        PlayerProfileViewController *playerView = [self.storyboard instantiateViewControllerWithIdentifier:@"profile_view"];
        [self.navigationController pushViewController:playerView animated:YES];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.

    
    CWFData *dataObj = [CWFData sharedInstance];
    tempGlobalArray = [[NSArray alloc] initWithArray:[dataObj.getGlobalLeaderboard valueForKey:@"users"]];
    tempFriendsArray = [[NSArray alloc] initWithArray:[dataObj.getFriendsLeaderboard valueForKey:@"records"]];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
